home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
remote.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
5KB
|
144 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import os
from quodlibet.util import fifo
from quodlibet import const
try:
from quodlibet.util import winpipe
except ImportError:
winpipe = None
class RemoteError(Exception):
pass
class RemoteBase(object):
'''A thing for communicating with existing instances of ourself.'''
def __init__(self, app, cmd_registry):
'''Takes an Application and CommandRegistry'''
raise NotImplemented
def remote_exists(self):
'''See if another instance exists'''
raise NotImplemented
remote_exists = classmethod(remote_exists)
def send_message(cls, message):
"""Send data to the existing instance if possible and returns
a response.
Raises RemoteError in case the message couldn't be send or
there was no response.
"""
raise NotImplemented
send_message = classmethod(send_message)
def start(self):
'''Start the listener for other instances'''
raise NotImplemented
def stop(self):
'''Stop the listener for other instances'''
raise NotImplemented
class QuodLibetWinRemote(RemoteBase):
_NAME = 'quodlibet'
def __init__(self, app, cmd_registry):
self._app = app
self._cmd_registry = cmd_registry
self._server = winpipe.NamedPipeServer(self._NAME, self._callback)
def remote_exists(cls):
return winpipe.pipe_exists(cls._NAME)
remote_exists = classmethod(remote_exists)
def send_message(cls, message):
try:
winpipe.write_pipe(cls._NAME, message)
except EnvironmentError:
e = None
raise RemoteError(e)
send_message = classmethod(send_message)
def start(self):
self._server.start()
def stop(self):
self._server.stop()
def _callback(self, data):
self._cmd_registry.handle_line(self._app, data)
class QuodLibetUnixRemote(RemoteBase):
_PATH = const.CONTROL
def __init__(self, app, cmd_registry):
self._app = app
self._cmd_registry = cmd_registry
self._fifo = fifo.FIFO(self._PATH, self._callback)
def remote_exists(cls):
return fifo.fifo_exists(cls._PATH)
remote_exists = classmethod(remote_exists)
def send_message(cls, message):
try:
return fifo.write_fifo(cls._PATH, message)
except EnvironmentError:
e = None
raise RemoteError(e)
send_message = classmethod(send_message)
def start(self):
self._fifo.open()
def stop(self):
self._fifo.destroy()
def _callback(self, data):
try:
(data, path) = fifo.split_message(data)
except ValueError:
for line in data.splitlines():
self._cmd_registry.handle_line(self._app, line)
with open(path, 'wb') as h:
response = self._cmd_registry.handle_line(self._app, data)
if response is not None:
h.write(response)
if os.name == 'nt':
Remote = QuodLibetWinRemote
else:
Remote = QuodLibetUnixRemote